package com.doraro.platform.module.device.model.param.cond;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.doraro.platform.common.beans.params.ValidateGroups;
import com.doraro.platform.module.device.model.entity.RepairOrder;
import com.doraro.platform.module.device.model.enums.OrderStatus;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Objects;

/**
 * 维修建议分页条件
 */
@Data
public class OrderCond implements BaseCond<RepairOrder> {
    @ApiModelProperty(value = "维修单号")
    @TableId(type = IdType.UUID)
    private String id;

    @NotNull(message = "故障设备编号不能为空", groups = ValidateGroups.Create.class)
    @ApiModelProperty(value = "故障设备编号")
    private String deviceId;
    @NotBlank(message = "故障设备不能为空", groups = ValidateGroups.Create.class)
    @ApiModelProperty(value = "故障设备名称")
    private String name;
    @ApiModelProperty(value = "故障设备分类")
    @NotBlank(message = "故障设备分类不能为空", groups = ValidateGroups.Create.class)
    private String type;

    @ApiModelProperty(value = "故障时间", example = "2018-04-11")
    private LocalDate breakdownTime;

    @ApiModelProperty(value = "生产时间", example = "2017-04-11")
    private LocalDate productionTime;

    @ApiModelProperty(value = "分派维修工程师编号")
    private String engineerId;

    @ApiModelProperty(value = "分配处理员（设备管理人员id)")
    private String managerId;

    @ApiModelProperty(value = "申请人编号")
    private String createUserId;

    @ApiModelProperty(value = "分派时间")
    private LocalDateTime dispatchTime;

    @ApiModelProperty(value = "创建时间(报修时间)")
    private LocalDateTime createTime;

    @ApiModelProperty(value = "完成时间")
    private LocalDateTime completeTime;


    @ApiModelProperty(value = "0-维修申请中 1-设备维修中 2-维修完成，请求确认中  3-维修完成")
    private OrderStatus orderStatus;

    @Override
    public LambdaQueryWrapper<RepairOrder> condition() {
        return new LambdaQueryWrapper<RepairOrder>()
                .like(Objects.nonNull(id), RepairOrder::getId, id)
                .like(Objects.nonNull(deviceId), RepairOrder::getDeviceId, deviceId)
                .like(Objects.nonNull(engineerId), RepairOrder::getEngineerId, engineerId)
                .like(Objects.nonNull(managerId), RepairOrder::getManagerId, managerId)
                .like(Objects.nonNull(createUserId), RepairOrder::getCreateUserId, createUserId)
                .like(Objects.nonNull(name), RepairOrder::getName, name)
                .like(Objects.nonNull(type), RepairOrder::getType, type)
                .eq(Objects.nonNull(breakdownTime), RepairOrder::getBreakdownTime, breakdownTime)
                .eq(Objects.nonNull(dispatchTime), RepairOrder::getDispatchTime, dispatchTime)
                .eq(Objects.nonNull(createTime), RepairOrder::getCreateTime, createTime)
                .eq(Objects.nonNull(completeTime), RepairOrder::getCompleteTime, completeTime)
                .eq(Objects.nonNull(orderStatus), RepairOrder::getOrderStatus, orderStatus)
                .eq(Objects.nonNull(productionTime), RepairOrder::getProductionTime, productionTime)
                ;
    }
}
